var Ue = {};
Ue.Common = {
    dataTable: {
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "sDom": '<""l>t<"F"ip>',
        "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "全部"]],
        "deferRender": true,
        "processing": true,
        "serverSide": true,        
        "oLanguage": {
            "sLengthMenu": "每页显示 _MENU_ 条记录",
            "sZeroRecords": "抱歉， 没有找到",
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
            "sInfoEmpty": "没有数据",
            "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            },
            "sZeroRecords": "没有检索到数据。"
        }
    },
    init: function () {

    },
    modal: function (url) {
        $.get(url, {}, function (rs, status) {
            if (!rs.ret) {
                $("#notice_error").html(rs.error).parent().removeClass('hidden');
                return true;
            }
            if (rs.id) {
                $("#" + rs.id).remove();
            }
            $("#div_modal").append(rs.html);
        });
    },
    warning: function (msg) {
        bootbox.dialog({
            message: "<div class='row modalline'><div class='col-xs-1'><span class='glyphicon glyphicon-remove-circle red'></span></div><div class='col-xs-11'>" + msg + "</div></div>",
            title: "操作失败",
            onEscape: function () {
            },
            show: true,
            backdrop: true,
            closeButton: true,
            animate: true,
            className: "btbox_errorinfo",
        });
    },
    success: function (msg) {
        bootbox.dialog({
            message: "<div class='row modalline'><div class='col-xs-1'><span class='glyphicon glyphicon-ok-circle green'></span></div><div class='col-xs-11'>" + msg + "</div></div>",
            title: "操作成功",
            onEscape: function () {
                window.location.reload();
            },
            show: true,
            backdrop: true,
            closeButton: true,
            animate: true,
            className: "btbox_okinfo"
        });
    },
    unauthorized: function (msg) {
        bootbox.dialog({
            message: "<div class='row modalline'><div class='col-xs-1'><span class='glyphicon glyphicon-remove-circle red'></span></div><div class='col-xs-11'>" + msg + "</div></div>",
            title: "未授权的操作",
            onEscape: function () {
            },
            show: true,
            backdrop: true,
            closeButton: true,
            animate: true,
            className: "btbox_errorinfo",
        });
    },
    submit: function (formName) {
        var form = $("#" + formName);
        var data = form.formSerialize();
        var obj = form.formToArray();
        console.log(form.attr('url'));
        $.post(form.attr('url'), data, function (rs, status) {
            if (rs.ret == 401) {
                Ue.Common.unauthorized(data.error);
                return true;
            }
            if (rs.error) {
                Ue.Common.warning(rs.error);
            }
        });
    },
    select: function (id) {
        $("#" + id).addClass("active");
    },
    keepLive: function () {
        var t = Math.random();
        $.post('/keepLive?_t=' + t, {"time": t}, function (rs, status) {

        });
        setTimeout("Ue.Common.keepLive()", 120000);
    },
    extend: function (destination, source) {
        for (var property in source) {
            destination[property] = source[property];
        }
        return destination;
    }
}
$(function () {
    setTimeout("Ue.Common.keepLive()", 10000);
});